package zhaoyong.wang.tlias.controller;

import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import zhaoyong.wang.tlias.pojo.Dept;
import zhaoyong.wang.tlias.pojo.Result;
import zhaoyong.wang.tlias.service.impl.DeptService;

import java.util.List;
import java.util.logging.Logger;

@RestController
@Slf4j
public class DeptController {
    @Autowired
    private DeptService deptService;

    //private static Logger log = (Logger) LoggerFactory.getLogger(DeptController.class);
   // @RequestMapping(value = "/depts",method = RequestMethod.GET)
    @GetMapping("/depts")
    public Result list(){
        log.info("查询所有部门");
        List<Dept> deptList = deptService.list();
        return Result.success(deptList);
    }
    @DeleteMapping("/depts/{id}")
    public Result Delete(@PathVariable  Integer id){
        log.info("删除部门");
        deptService.delete(id);
        return Result.success();
    }
    @PostMapping("/depts")
    public Result update(@RequestBody Dept dept){
        log.info("新增部门");
        deptService.update(dept);
        return Result.success();

        }
    @GetMapping("/depts/{id}")
    public Result select(@PathVariable Integer id){
        log.info("根据id查询部门信息");
        Dept name = deptService.select(id);
        return Result.success(name);
    }
    @PutMapping("/depts")
    public Result updates(@RequestBody Dept dept){
        log.info("更新部门信息");
        deptService.gengxin(dept);
        return Result.success();
    }
}
